package com.mj.activity.publish;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.mj.R;
import com.mj.base.BaseActivity;
import com.mj.util.Constant;
import com.mj.util.DensityUtil;

public class PublishActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_publish);
		init();
	}

	@Override
	protected void onResume() {
		super.onResume();
		aq.id(R.id.imageView1).visible();
		aq.id(R.id.imageView2).visible();
	}

	@Override
	protected void onPause() {
		super.onPause();
		aq.id(R.id.imageView1).gone();
		aq.id(R.id.imageView2).gone();
	}

	private void init() {
		// 将页面宽度设置为全屏
		WindowManager.LayoutParams p = getWindow().getAttributes();
		p.width = (int) (DensityUtil.getDisplay(this).widthPixels * 0.9);
		p.height = (int) (DensityUtil.getDisplay(this).heightPixels * 0.9);
		// 设置生效
		getWindow().setAttributes(p);
		// 去除背景框
		getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		aq.id(R.id.imageView1).clicked(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(PublishActivity.this, "“该功能尚未开放，敬请期待”", Toast.LENGTH_LONG).show();
			}
		});
		aq.id(R.id.imageView2).clicked(this, "pic");
		// 是否直接打开选择图片
		String pic = getIntent().getStringExtra("pic");
		if (!TextUtils.isEmpty(pic)) {
			pic();
		}
	}

	/***
	 * 选择上传图片来源
	 */
	public void pic() {
		Intent intent = new Intent(this, PicActivity.class);
		startActivityForResult(intent, Constant.PIC);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode != RESULT_OK) {
			finish();
			return;
		}
		switch (requestCode) {
		case Constant.PIC:
			// 发信息页面
			data.setClass(this, PubtxtActivity.class);
			startActivity(data);
			finish();
			break;
		case Constant.VIDEO:
			break;
		}
	}

}